package com.swu.pad.system.service.impl;

import java.io.File;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.swu.pad.system.dao.HelpDocumentDao;
import com.swu.pad.system.entity.HelpDocument;
import com.swu.pad.system.service.HelpDocumentService;


@Service
@Transactional
public class HelpDocumentServiceImpl implements HelpDocumentService {
   	  
	@Autowired
	private HelpDocumentDao helpDocumentDao;
	
	//上传文件
	@Override
	public void uploadHelpFile(HelpDocument helpDocument) {
		 helpDocumentDao.save(helpDocument);
	}
    
	//查询所有文件
	@Override
	public List<HelpDocument> findAllFile() {
		return helpDocumentDao.findAll();
	}
    
	//根据id 删除 文件
	@Override
	public void deleteFileById(String fileId) {
		HelpDocument helpDocument=helpDocumentDao.findOne(fileId);
		File f = new File(helpDocument.getFilepath()+helpDocument.getFilename());  // 输入要删除的文件位置
		if(f.exists()){
		    f.delete();
		}
		helpDocumentDao.delete(fileId);
	}
   
	//根据 id 查询文件
	@Override
	public HelpDocument findFileById(String fileId) {
       return  helpDocumentDao.findOne(fileId); 		
	}

}
